package com.tom.demo.common.response;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@SuppressWarnings("all")
@Data
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(value = "统一返回结果")
public class Result implements Serializable {
    private static final long serialVersionUID = 134684324363040701L;
    /**
     * 编码：2000成功，其它数字为失败
     */
    @ApiModelProperty(value = "业务码：2000成功，其它数字为失败")
    private Integer code;
    /**
     * 信息
     */
    @ApiModelProperty(value = "信息")
    private String msg;
    /**
     * 数据
     */
    @ApiModelProperty(value = "数据")
    private Object data;


    public static  Result success(Object object) {
        Result r = new Result();
        r.data = object;
        r.code = 2000;
        r.msg = "操作成功";
        return r;
    }
    public static  Result success() {
        Result r = new Result();
        r.code = 2000;
        r.msg = "操作成功";
        return r;
    }
    public static  Result error(String msg) {
        Result r = new Result();
        r.msg = msg;
        r.code = 5000;
        return r;
    }
    public static  Result error(String msg, Integer code) {
        Result r = new Result();
        r.msg = msg;
        r.code = code;
        return r;
    }
    public static  Result error(String msg,Integer code,Object object) {
        Result r = new Result();
        r.msg = msg;
        r.code = code;
        r.data = object;
        return r;
    }
}